package cn.zshprint.serein.controller;

import cn.zshprint.serein.entity.Role;
import cn.zshprint.serein.entity.RoleUserRelation;
import cn.zshprint.serein.pojo.ResultBean;
import cn.zshprint.serein.service.RoleUserRelationService;
import org.springframework.lang.UsesSunMisc;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (RoleUserRelation)表控制层
 *
 * @author makejava
 * @since 2021-08-03 14:42:47
 */
@RestController
@RequestMapping("roleUserRelation")
public class RoleUserRelationController {
    /**
     * 服务对象
     */
    @Resource
    private RoleUserRelationService roleUserRelationService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne/{id}")
    public ResultBean<RoleUserRelation> selectOne(@PathVariable Integer id) {
        return new ResultBean<>(roleUserRelationService.getById(id));
    }

    @GetMapping("selectAll")
    public ResultBean<List<RoleUserRelation>> selectAll() {
        return new ResultBean<>(roleUserRelationService.list());
    }

    @PostMapping("saveOne")
    public ResultBean<Integer> saveOne(@RequestBody RoleUserRelation roleUserRelation) {
        return new ResultBean<Integer>(roleUserRelationService.save(roleUserRelation) ? roleUserRelation.getId() : -1);
    }

    @PutMapping("updateOne")
    public ResultBean<Integer> updateOne(@RequestBody RoleUserRelation roleUserRelation) {
        return new ResultBean<Integer>(roleUserRelationService.updateById(roleUserRelation) ? roleUserRelation.getId() : -1);
    }

    @DeleteMapping("deleteOne/{id}")
    public ResultBean<Integer> deleteOne(@PathVariable Integer id) {
        return new ResultBean<Integer>(roleUserRelationService.removeById(id) ? id : -1);
    }
}